import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.cfg.Configuration;
import org.hibernate.metadata.ClassMetadata;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ttq
 * Date: 13-7-9
 * Time: 下午8:18
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    private static final SessionFactory ourSessionFactory;

    static {
        try {
            ourSessionFactory = new Configuration().addResource("hibernate.cfg.xml").buildSessionFactory();
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession() throws HibernateException {
        return ourSessionFactory.openSession();
    }

    public static void main(final String[] args) throws Exception {
        XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
        IAopService hello = (IAopService) factory.getBean("aopService");
        hello.withAop();
        hello.withoutAop();
        factory.destroySingletons();
    }
}
